<template>
  <div class="lottery-container">
<!--    <h1>随机抽奖</h1>-->
    <el-button type="primary" size="large" class="lottery-button" @click="startLottery">
      开始抽取职业
    </el-button>
    <div class="lottery-numbers" v-if="lotteryNumbers">
      <div class="number-box">
        <img :src="lotteryNumbers.imageUrl" style="width: 40px; height: 40px;">
        {{ lotteryNumbers.label }}
      </div>
    </div>
  </div>
  <skill v-if="lotteryNumbers" ref="childRef" :job="lotteryNumbers"/>
</template>

<script setup>
import {ref} from 'vue'
import Skill from "@/components/skill.vue";
const childRef = ref(null)
const prop = defineProps({
  message: []
})
const lotteryNumbers= ref(null)

const startLottery = () => {
  if(prop.message.length){
    lotteryNumbers.value = generateRandomNumbers(1, prop.message.length)
    setTimeout(()=>{
      childRef.value.changeItems(lotteryNumbers.value)
    },50)
  }else{
    ElMessage.error('请先选择职业')
  }
}

const generateRandomNumbers = (count, max) => {
  const numbers = (Math.floor(Math.random() * max))
  return prop.message[numbers]
}
</script>

<style scoped>
.lottery-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.lottery-numbers {
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  grid-gap: 16px;
  margin-bottom: 32px;
}

.number-box {
  width: 200px;
  height: 80px;
  background-color: #f5f5f5;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: bold;
}

.lottery-button {
  font-size: 20px;
  padding: 12px 32px;
  margin: 24px;
}
</style>